package br.ufrj.ppgi.infovis.util;

import java.lang.reflect.Array;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class UnorderedPair<T> {
    private final Set<T> set;

    public UnorderedPair(T a, T b) {
         set = new HashSet<T>();
         set.add(a);
         set.add(b);
    }

    public boolean equals(Object b) {
    	UnorderedPair<T> other;
    	try {
    	   other = (UnorderedPair<T>) b;
    	} catch (ClassCastException e) {
    		return false;
    	}
    	
    	return this.set.equals(other.set);
    }

    public int hashCode() {
        return set.hashCode();
    }
    
    @SuppressWarnings("unchecked")
	public T[] getElements(){
    	Iterator<T> it = set.iterator();
    	T typeVar = it.next();
    	
    	return  set.toArray((T[]) Array.newInstance(typeVar.getClass(),0));
    }
}
